<template>
  <div class="about">
    <p>温州理工滨海校区</p>
    <div class="search-container">
      <input v-model="studentId" type="text" placeholder="请输入学号" />
      <button @click="searchStudent">搜索</button>
    </div>
    <div v-if="studentInfo" class="student-info">
      <p>学生信息</p>
      <p>学号: {{ studentInfo.id }}</p>
      <p>姓名: {{ studentInfo.name }}</p>
      <p>年龄: {{ studentInfo.age }}</p>
      <p>专业: {{ studentInfo.class }}</p>
      <!-- 其他学生信息字段 -->
    </div>
    <div v-if="errorMessage" class="error-message">
      {{ errorMessage }}
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      studentId: '',
      studentInfo: null,
      errorMessage: ''
    };
  },
  methods: {
    searchStudent() {
      // 模拟学生数据，实际应用中应从后端API获取
      const students = [
        { id: '123456', name: '李小明', class: '计算机科学' ,age:18},
        { id: '654321', name: '张小红', class: '软件工程',age:22 },
        // 其他学生数据
      ];

      const foundStudent = students.find(student => student.id === this.studentId);

      if (foundStudent) {
        this.studentInfo = foundStudent;
        this.errorMessage = '';
      } else {
        this.studentInfo = null;
        this.errorMessage = '未找到该学号的学生信息';
      }
    }
  }
};
</script>

<style scoped>
.search-container {
  margin-top: 20px;
}

.search-container input {
  padding: 8px;
  width: 200px;
  margin-right: 10px;
}

.search-container button {
  padding: 8px 16px;
}

.student-info {
  margin-top: 20px;
}

.error-message {
  margin-top: 20px;
  color: red;
}
</style>